home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / GRABMAIL.SLT < prev    next >
Text File  |  1992-03-20  |  18KB  |  539 lines

  1. //-----------------------------------------------------------
  2. // GrabMail.SL?   Telix script to fetch mail from a BBS.
  3. //
  4. // Please look at the comments through the whole file, and modify to
  5. // suit your needs, BEFORE you use it. Then recompile with CS GrabMail.
  6. //-----------------------------------------------------------
  7.  
  8. // If you have suggestions for improving this script, please suggest
  9. // improvements to me via old-fashioned snail-mail to:
  10.  
  11. // Author:  Inge Vabekk
  12. //          Hamangskogen 108
  13. //          N-1300 SANDVIKA
  14. //          NORWAY
  15. //          tel. (472) 546 396
  16.  
  17. str command [10]="Command:"  // Command prompt.
  18.    ,input   [80]             // One input line.
  19.    ,f0      [14]             // Filename for download.
  20.    ,maildir [64]             // Mail directory or download directory.
  21.    ,myprot   [2]             // My protocol
  22.    ,hisprot  [2]             // PCB's protocol
  23.                              // For the Global storage:
  24.    ,global   []="GLOBAL"     // Global script.
  25.    ,UpDownF  []="UPDOWNF"    // Get/Put File script.
  26.    ,PutLine  []="PUTLINE"    // PutLine script.
  27.    ,bbstype  []="BTYPE"      // BBS type.
  28.    ,short    []="SHORT"      // Short BBS name.
  29.    ,Cprot    []="CPROT"      // Current protocol.
  30.    ,Hprot    []="HPROT"      // "His" protocol.
  31.    ,version  []="BBSver"     // PCB version
  32.    ,mdir     []="MDIR"       // Mail directory.
  33.    ,rmode    []="RMODE"      // Read mode for MBBS
  34.    ,prompt   []="PROMPT"     // Current command prompt.
  35.    ;     
  36.  
  37. int tol = 900                            // No activity for 90 seconds
  38.    ,tmark                                // makes script time out. 
  39.    ,stat                                 // For tracking.
  40.    ,BBSver                               // PCBoard version.
  41.    ,MORE                                 // More messages if TRUE.
  42.    ,pcb, mbbs, rbbs, opus, fido, crcs    // different kinds of systems
  43.    ,protocol                             // Current protocol.
  44.    ,file                                 // File handle
  45.    ,Enter=13                             // Code for CR (Enter)
  46.    ;
  47.  
  48. //-----------------------------------------------------------
  49. // GrabMail script is entered here.                                   
  50. //-----------------------------------------------------------
  51.  
  52. main()
  53. {
  54. int i;
  55.  
  56. // This script is assumed to be called ONLY after logon
  57. // to perform routine tasks.
  58.  
  59. // Only if online.
  60.  
  61.   if (!carrier())  
  62.   { failtone();
  63.     status_wind ("T²: YOU CAN'T FETCH MAIL IF YOU'RE OFFLINE!",20);
  64.     return (-1);
  65.   }
  66.   
  67.   entry();                        // Updates status bar.
  68.  
  69. // Check which BBS system.
  70.  
  71.   read (bbstype,input);
  72.   mbbs = pcb = rbbs = opus = fido = crcs = 0;
  73.   if      (input == "MBBS") mbbs = 1;
  74.   else if (input == "PCB" ) pcb = 1;
  75.   else if (input == "RBBS") rbbs = 1;
  76.   else if (input == "OPUS") opus = 1;
  77.   else if (input == "FIDO") fido = 1;
  78.   else if (input == "CRCS") crcs = 1;
  79.   else                                          
  80.   { wrongBBS(input);                   // Doesn't match script!
  81.     return (-1);
  82.   }
  83.  
  84.   read (prompt,command);               // Get command prompt.
  85.   read (version,input);
  86.   BBSver = subchr (input,0);           // Get PCBoard version.
  87.   read (cprot,myprot);                 // Get protocol.
  88.   protocol = subchr (myprot,0);        // Must be INT.
  89.   read (hprot,hisprot);
  90.   read (mdir,maildir);                 // Get mail directory.
  91.   input = maildir;                     // Check it out.
  92.   strcat (input,"NPU.TMP");            // Try to create a file there.
  93.   if ((i=fopen(input,"w")) > 0)
  94.   { fclose (i);
  95.     fdelete (input);
  96.   }
  97.   else
  98.   { prints ("");
  99.     printsc ("T²: Wrong MAIL directory: ");
  100.     printsc (maildir);
  101.     prints ("! Can't grab messages!");
  102.     return (0);
  103.   }
  104.  
  105. // ZIPM or GRAB messages.
  106. //-----------------------------------------------------------
  107.  
  108.   MORE = 1;
  109.   while (MORE)
  110.   { f0 = "";                      // No name yet.
  111.     if (mbbs)
  112.       grab();
  113.     else if (pcb)
  114.     { if (BBSver < 145)
  115.         zipm();
  116.       else
  117.         raz();                    // PCBoard 14.5 and later
  118.     }
  119.   }
  120.   return (0);
  121. }
  122.  
  123. //-----------------------------------------------------------
  124. // This routine GRABS messages from MBBS.
  125. //-----------------------------------------------------------
  126.  
  127. grab()
  128. {
  129. str filename[]="ilename: ";            // Look for this text.
  130. int t1, t2, t3, t4, mm, nm1, nm2, mess;
  131.  
  132.   if (read (rmode,hisprot) < 0)
  133.     hisprot = "M";                     // Get read mode.
  134.   input = "R MODE ";
  135.   strcat (input,hisprot);
  136.   strcat (input,";D A");
  137.   call (PutLine,input, Enter);         // Read and dump all messages.
  138.  
  139.   MORE = 0;                            // Donit. 
  140.   mess = 1;                            // Assume messages.
  141.   t1 = track ("command!", 0);          // Define new tracks.
  142.   t2 = track (command, 0);             // Next command.
  143.   t3 = track ("on disk!", 0);          // Not enough space for GRAB.
  144.   t4 = track ("Dumping ", 0);          // Still dumping....
  145.   nm1 = track ("<0> messa", 0);        // No messages.
  146.   nm2 = track ("<0> new m", 0);        // No new messages.
  147.   mm = track ("More Messages", 0);     // More messages.
  148.  
  149.   tmark = timer_start (tol);           // Give me a minute.
  150.  
  151.   while ((stat=trig()) > 0)            // answer any questions
  152.   { if (stat == t1)                    // Illegal command (line error!)
  153.       call (PutLine,"R MODE F D A", Enter); // Send a new command.
  154.  
  155.     else if (stat == t2)               // Next command.
  156.       break;
  157.  
  158.     else if (stat == t3)                 // Disc is full - Can't GRAB.
  159.     { mess = 0;
  160.       break;
  161.     }
  162.     else if (stat == t4)                 // Still dumping;
  163.       ;                                // this just postpones timeout.
  164.  
  165.     else if (stat==nm1 || stat==nm2)   // No more messages.
  166.     { mess = 0;
  167.       MORE = 0;
  168.     }
  169.     else if (stat == mm)                 // More messages next time.
  170.       MORE = 1;
  171.  
  172.   }
  173.   release();
  174.   if (mess)                            // Messages to fetch:
  175.   { call (PutLine,"SE", Enter);
  176.     if (waitfor (filename,60))
  177.       get_file(filename);              // Get the file.
  178.   }
  179. }
  180.  
  181. //-----------------------------------------------------------
  182. // This routine fetches messages from PCBoard rev. >= 14.5.
  183. //-----------------------------------------------------------
  184.  
  185. raz()
  186. {
  187. str filename[]="elected: ";              // Look for this text.
  188.  
  189. int mm                                   // More messages.
  190.    ,messages                             // Messages to fetch if == 1.
  191.    ,co         // Command
  192.    ,dot        // More coming....
  193.    ,ccm        // Compressing captured mail
  194.    ,ec1, ec2   // ENTER to continue
  195.    ,ntd        // Nothing to download.
  196.    ,Def        // Default protocol
  197.    ;
  198.  
  199.   MORE = 0;                              // Donit. 
  200.   messages = -1;                         // Command not sent.
  201.  
  202. // Track the following:
  203.  
  204.   co  = track (command,0);               // Back to command.
  205.   Def = track ("col Desired",0);         // Default protocol....
  206.   ec1 = track (")=continue?",0);         // Press ENTER.
  207.   ec2 = track ("o download?",0);         // Press ENTER.
  208.   ccm = track ("ssing captu",0);         // Compressing captured mail.
  209.   ntd = track ("- nothing t",0);         // Nothing to download.
  210.   mm  = track (" limit reac",0);         // Max. limit reached.
  211.   dot = track ("Scan",0);                // Signals that it's working.
  212.   file= track (filename,0);              // Filename comes now.
  213.  
  214.   tol = 1200;
  215.   input = "T ";
  216.   strcat (input,hisprot);                // Set protocol. Not really necessary
  217.   call (PutLine, input, Enter);          // every time, but we can't know
  218.                                          // when it would be.
  219.   do
  220.   { tmark = timer_start (tol);           // Set time-out.
  221.  
  222.     while ((stat=trig()) > 0)            // answer any questions.
  223.     { if (stat == co)                    // Command?
  224.       { if (messages < 0) 
  225.         { call (PutLine,"R A Z", Enter); // Send READ ALL, then ZIP.
  226.           continue;
  227.         }
  228.